package com.crazymo.binderpool.exception;

/******************************************************************
 * @Copyright : (C), 2001-2021, ZHEJIANG DAHUA TECHNOLOGY CO.,LTD
 * @FileName : MyException
 * @Author : 224967  Crazy.Mo
 * @Date : 2022/1/25 10:28
 * @Description :    
 * @History :
 * <author>  <time>  <version>   <desc>
 * 224967    修改时间    版本号       描述
 ******************************************************************/

public enum MoErrorEnum implements IError {
    /** 未指明的异常 */
    UNSPECIFIED(-99, "unknown exception"),
    ENGINE_UNKNOWN_ERROR(-9999,"unknown inner error"),

    // 通用异常

    PARAM_TYPE_ERROR(400, "error type param"),
    PARAM_IS_NULL(4001,"param can't be null"),
    PARAM_NOT_INIT(4002,"param isn't init yet"),
    PARAM_IS_EMPTY(4003,"param can't be empty"),
    PARAM_IS_ILLEGAL(4004,"param is illegal"),
    ENGINE_NOT_READY(500,"engine not ready"),
    ENGINE_NOT_INIT(5001,"engine not init"),
    ;

    private final int code;
    private final String message;

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    MoErrorEnum(int code, String message) {
        this.code = code;
        this.message = message;
    }
    /**
     * 根据编码查询枚举。
     *
     * @param code 编码。
     * @return 枚举。
     */
    public static MoErrorEnum getByCode(int code) {
        for (MoErrorEnum value : MoErrorEnum.values()) {
            if (code== value.getCode()) {
                return value;
            }
        }
        return UNSPECIFIED;
    }


    /**
     * 枚举是否包含此code
     * @param code 枚举code
     * @return 结果
     */
    public static Boolean contains(int code){
        for (MoErrorEnum value : MoErrorEnum.values()) {
            if (code==value.getCode()) {
                return true;
            }
        }
        return  false;
    }
}
